const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

//将时间'2021-03-10 09:10:44'转化为时间戳
const getTargetTime=(t)=>{
  var d = t.split(" ")[0],
    h = t.split(" ")[1],
    date = new Date()

  date.setYear(d.split("-")[0]);
  date.setMonth(d.split("-")[1] - 1);
  date.setDate(d.split("-")[2])

  date.setHours(h.split(":")[0])
  date.setMinutes(h.split(":")[1])
  date.setSeconds(h.split(":")[2])

  return date.getTime()    
}

let reg=/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(16[0-9]{1})|(19[0-9]{1}))+\d{8})$/;

module.exports = {
  formatTime,
  reg,
  getTargetTime,
}
